package com.dolphin.crossbrowser;

import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.webkit.ValueCallback;

import org.xwalk.core.XWalkJavascriptResult;
import org.xwalk.core.XWalkUIClient;
import org.xwalk.core.XWalkView;

public class XWalkUIClientImpl extends XWalkUIClient {
    public static final String TAG = "XWalkUIClientImpl";

    XWalkUIClientImpl(XWalkView view) {
        super(view);
    }

    @Override
    public boolean onCreateWindowRequested(XWalkView view, InitiateBy initiator, ValueCallback<XWalkView> callback) {
        Log.d(TAG, "onCreateWindowRequested");
        return super.onCreateWindowRequested(view, initiator, callback);
    }

    @Override
    public void onIconAvailable(XWalkView view, String url, Message startDownload) {
        Log.d(TAG, "onIconAvailable url:" + url);
        startDownload.sendToTarget();
        super.onIconAvailable(view, url, startDownload);
    }

    @Override
    public void onReceivedIcon(XWalkView view, String url, Bitmap icon) {
        Log.d(TAG, "onReceivedIcon url:" + url);
        super.onReceivedIcon(view, url, icon);
    }

    @Override
    public void onRequestFocus(XWalkView view) {
        Log.d(TAG, "onRequestFocus");
        super.onRequestFocus(view);
    }

    @Override
    public void onJavascriptCloseWindow(XWalkView view) {
        Log.d(TAG, "onJavascriptCloseWindow");
        super.onJavascriptCloseWindow(view);
    }

    @Override
    public boolean onJavascriptModalDialog(XWalkView view, JavascriptMessageType type, String url, String message, String defaultValue, XWalkJavascriptResult result) {
        Log.d(TAG, "onJavascriptModalDialog message:" + message);
        return super.onJavascriptModalDialog(view, type, url, message, defaultValue, result);
    }

    @Override
    public void onFullscreenToggled(XWalkView view, boolean enterFullscreen) {
        Log.d(TAG, "onFullscreenToggled enterFullscreen:" + enterFullscreen);
        super.onFullscreenToggled(view, enterFullscreen);
    }

    @Override
    public void openFileChooser(XWalkView view, ValueCallback<Uri> uploadFile, String acceptType, String capture) {
        Log.d(TAG, "openFileChooser acceptType:" + acceptType);
        super.openFileChooser(view, uploadFile, acceptType, capture);
    }

    @Override
    public void onScaleChanged(XWalkView view, float oldScale, float newScale) {
        Log.d(TAG, "onScaleChanged oldScale:" + oldScale + " newScale:" + newScale);
        super.onScaleChanged(view, oldScale, newScale);
    }

    @Override
    public boolean shouldOverrideKeyEvent(XWalkView view, KeyEvent event) {
        Log.d(TAG, "shouldOverrideKeyEvent event:" + event.toString());
        return super.shouldOverrideKeyEvent(view, event);
    }

    @Override
    public void onUnhandledKeyEvent(XWalkView view, KeyEvent event) {
        Log.d(TAG, "onUnhandledKeyEvent event:" + event.toString());
        super.onUnhandledKeyEvent(view, event);
    }

    @Override
    public boolean onConsoleMessage(XWalkView view, String message, int lineNumber, String sourceId, ConsoleMessageType messageType) {
        Log.d(TAG, "onConsoleMessage lineNumber:" + lineNumber + " message:" + message);
        return super.onConsoleMessage(view, message, lineNumber, sourceId, messageType);
    }

    @Override
    public void onReceivedTitle(XWalkView view, String title) {
        Log.d(TAG, "onReceivedTitle title:" + title);
        super.onReceivedTitle(view, title);
    }

    @Override
    public void onPageLoadStarted(XWalkView view, String url) {
        Log.d(TAG, "onPageLoadStarted url:" + url);
        super.onPageLoadStarted(view, url);
    }

    @Override
    public void onPageLoadStopped(XWalkView view, String url, LoadStatus status) {
        Log.d(TAG, "onPageLoadStopped url:" + url + " status:" + status);
        super.onPageLoadStopped(view, url, status);
    }

    @Override
    public boolean onJsAlert(XWalkView view, String url, String message, XWalkJavascriptResult result) {
        Log.d(TAG, "onJsAlert message:" + message);
        return super.onJsAlert(view, url, message, result);
    }

    @Override
    public boolean onJsConfirm(XWalkView view, String url, String message, XWalkJavascriptResult result) {
        Log.d(TAG, "onJsConfirm message:" + message);
        return super.onJsConfirm(view, url, message, result);
    }

    @Override
    public boolean onJsPrompt(XWalkView view, String url, String message, String defaultValue, XWalkJavascriptResult result) {
        Log.d(TAG, "onJsPrompt message:" + message);
        return super.onJsPrompt(view, url, message, defaultValue, result);
    }
}
